<template>
  <!--学科新闻-->
  <div class="journalism">
    <!--统一样式-->
    <div class="journalism_title">
      <div class="journalism_title_icon">
        <img src="./../../../assets/home/xuekexinwen.svg" alt="" />
      </div>
      <p class="journalism_title_font">学科新闻</p>
      <div class="journalism_title_more" @click="handelLink">
        更多 <i class="el-icon-d-arrow-right"></i>
      </div>
    </div>
    <!--内容-->
    <div class="journalism_carousel">
      <el-carousel>
        <el-carousel-item v-for="item in journalismList" :key="item.id">
          <div class="carousel-content">
            <div class="image-container">
              <img
                v-if="!!item.img"
                :src="item.img"
                alt=""
                @click="handelNews(item)"
                style="width: 100%; height: 400px; object-fit: cover"
              />
            </div>
            <div class="journalism_text">
              <p>{{ item.title }}</p>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>

<script>
import { getCourseNewsList } from "@/api/home";
export default {
  name: "journalism",
  data() {
    return {
      journalismData: {
        page: 1,
        size: 4,
      },
      journalismList: [],
    };
  },
  created() {},
  mounted() {
    this.getCourseNewsList();
  },
  methods: {
    // 获取列表
    getCourseNewsList() {
      getCourseNewsList(this.journalismData).then((response) => {
        if (response.data.code === 20000) {
          const { list } = response.data.results;
          this.journalismList = list ? list : [];
        }
      });
    },
    // 跳转到list页面
    handelLink() {
      this.$router.push({
        path: "/courseNews/courseNewsList",
        query: {
          routerName: "新闻列表",
        },
      });
    },
    handelNews(item) {
      if (item.url) {
        let path = window.location.protocol + "//" + item.url;
        window.open(path, "_blank");
      } else {
        this.$router.push({
          path: "/courseNews/newsDetails",
          query: {
            routerName: "新闻详情",
            newsId: item.id,
          },
        });
      }
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.journalism {
  // 删除或注释掉这些背景色设置
  // .el-carousel__item:nth-child(2n) {
  //   background-color: grey;
  // }
  // .el-carousel__item:nth-child(2n + 1) {
  //   background-color: #bbbbbb;
  // }

  .el-carousel__button {
    width: 12px;
    height: 12px;
    border-radius: 50%;
  }
}
</style>

<style rel="stylesheet/scss" lang="scss" scoped>
.journalism {
  width: 622px;
  height: 542px;
  color: #333;
  .journalism_title {
    margin-top: 40px;
    display: flex;
    padding-bottom: 15px;
    border-bottom: 2px solid #0a7b19;
    .journalism_title_icon {
      width: 32px;
      height: 32px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .journalism_title_font {
      font-weight: bold;
      font-size: 24px;
      margin-left: 15px;
      width: 100px;
    }
    .journalism_title_more {
      font-size: 12px;
      height: 32px;
      line-height: 32px;
      text-align: right;
      width: 475px;
      cursor: pointer;
    }
  }
  .journalism_carousel {
    .el-carousel {
      height: 400px;

      /deep/ .el-carousel__container {
        height: 100%;
      }
    }

    .carousel-content {
      display: flex;
      flex-direction: column;
      height: 100%;
    }

    .image-container {
      flex: 1;
      overflow: hidden;
    }

    .journalism_text {
      width: 100%;
      margin-top: 10px;
      text-align: center;
      background-color: #fff;

      p:first-child {
        font-size: 16px;
        font-weight: bold;
      }

      p:last-child {
        font-size: 14px;
        color: #666;
      }
    }
  }
}
</style>
